package com.fegin.util;

import io.swagger.annotations.ApiModelProperty;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Reflex {
    /**
     * 解析实体属性注解
     *
     * @param clazz
     */
    public static List   parseMethod(Class clazz,Map pa) {
        List list=new ArrayList();
        try {
            Field[] fields = clazz.getDeclaredFields();
            for (Field field:fields){
                ApiModelProperty methodAnnotation = field.getAnnotation(ApiModelProperty.class);

                if (methodAnnotation != null) {
                    Map map=new HashMap();
                    map.put("paramWay",pa.get("in"));
                    map.put("required",methodAnnotation.required());
                    map.put("name",field.getName());
                    map.put("type",field.getType().getSimpleName());
                    map.put("paramDoc",methodAnnotation.value());
                    list.add(map);
                }

            }
            return list;
       /*     for (Method method : clazz.getDeclaredMethods()) {
                ApiModelProperty methodAnnotation = method.getAnnotation(ApiModelProperty.class);

                if (methodAnnotation != null) {
                   System.err.println(methodAnnotation.value());
                }

            }*/
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) {
     //  System.err.println(parseMethod(StockUser.class));
    }
}